package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.entity.CoreEnterprise;
import com.corechina.apex_osswords.service.ICoreEnterpriseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 企业表 前端控制器
 * </p>
 *
 * @author cc
 * @since 2022-12-09
 */

@Api(tags = "企业管理")
@RestController
@RequestMapping("/core/enterprise")
public class CoreEnterpriseController {

    @Autowired
    private ICoreEnterpriseService iCoreEnterpriseService;

    @ApiOperation("新增")
    @SysLog("新增企业")
    @PostMapping("/add")
    public Response add(@RequestBody CoreEnterprise coreEnterprise) {
        return iCoreEnterpriseService.add(coreEnterprise);
    }

    @ApiOperation("编辑")
    @SysLog("编辑企业")
    @PutMapping("/update")
    public Response update(@RequestBody CoreEnterprise coreEnterprise) {
        coreEnterprise.setSerialNumber(null);
        if (iCoreEnterpriseService.updateById(coreEnterprise)) {
            return Response.ok();
        }
        return Response.error();
    }

    @ApiModelProperty("删除")
    @SysLog("删除企业")
    @DeleteMapping("/del")
    public Response del(Integer id) {
        if (iCoreEnterpriseService.removeById(id)) {
            return Response.ok();
        }
        return Response.error();
    }

    @ApiOperation("列表")
    @GetMapping("/getList")
    public Response getList(String name, Integer pageIndex, Integer pageSize) {
        return iCoreEnterpriseService.getList(name, pageIndex, pageSize);
    }

    @ApiOperation("详情")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return iCoreEnterpriseService.getOne(id);
    }

    @ApiOperation("编辑-企业")
    @SysLog("企业编辑企业")
    @PutMapping("/updateByEnterprise")
    public Response updateByEnterprise(@RequestBody CoreEnterprise coreEnterprise) {
        coreEnterprise.setSerialNumber(null);
        coreEnterprise.setShortName(null);
        coreEnterprise.setName(null);
        if (iCoreEnterpriseService.updateById(coreEnterprise)) {
            return Response.ok();
        }
        return Response.error();
    }
}

